<template>
  <div class="phnanp" @click="gettitl">
    <loading v-if="isLoading"></loading>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">男生排行榜</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="booklist">
        <ul>
          <li v-for="(item, s) in book_list" v-if="s < 1">
            <router-link :to="`/cs?id=${item.id}&title=${item.title}`">
              <em class="em-1 top-1">1</em>
              <div class="book-1">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p class="name-1">{{ item.author }}</p>
                <p class="p-1">{{ item.content }}</p>
                <p class="tag-1">
                  <span>连载</span>
                  <span>{{ item.category }}</span>
                </p>
              </div>
            </router-link>
          </li>
          <li v-for="(item, s) in book_list" v-if="(s > 0) & (s < 5)">
            <router-link
              :to="`/cs?id=${item.id}&title=${item.title}`"
              class="name-2"
              ><div class="text-2">
                <em class="em-1" :class="'top-' + (s + 1)">{{ s + 1 }}</em
                ><span>{{ item.title }}</span>
              </div></router-link
            >
          </li>
        </ul>
      </div>
    </div>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">女生排行榜</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="booklist">
        <ul>
          <li v-for="(item, s) in book_listn" v-if="s < 1">
            <router-link :to="`/cs?id=${item.id}&title=${item.title}`">
              <em class="em-1 top-1">1</em>
              <div class="book-1">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p class="name-1">{{ item.author }}</p>
                <p class="p-1">{{ item.content }}</p>
                <p class="tag-1">
                  <span>连载</span>
                  <span>{{ item.category }}</span>
                </p>
              </div>
            </router-link>
          </li>
          <li v-for="(item, s) in book_list" v-if="(s > 0) & (s < 5)">
            <router-link
              :to="`/cs?id=${item.id}&title=${item.title}`"
              class="name-2"
              ><div class="text-2">
                <em class="em-1" :class="'top-' + (s + 1)">{{ s + 1 }}</em
                ><span>{{ item.title }}</span>
              </div></router-link
            >
          </li>
        </ul>
      </div>
    </div>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">图书排行榜</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="booklist">
        <ul>
          <li v-for="(item, s) in book_listcb" v-if="s < 1">
            <router-link :to="`/cs?id=${item.id}&title=${item.title}`">
              <em class="em-1 top-1">1</em>
              <div class="book-1">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p class="name-1">{{ item.author }}</p>
                <p class="p-1">{{ item.content }}</p>
                <p class="tag-1">
                  <span>连载</span>
                  <span>{{ item.category }}</span>
                </p>
              </div>
            </router-link>
          </li>
          <li v-for="(item, s) in book_list" v-if="(s > 0) & (s < 5)">
            <router-link
              :to="`/cs?id=${item.id}&title=${item.title}`"
              class="name-2"
              ><div class="text-2">
                <em class="em-1" :class="'top-' + (s + 1)">{{ s + 1 }}</em
                ><span>{{ item.title }}</span>
              </div></router-link
            >
          </li>
        </ul>
      </div>
    </div>
    <!-- <div class="butom"></div> -->
  </div>
</template>
<script>
import { phFunc, reFunc } from "@/request/index";
import Loading from "@/components/loading/indexlist.vue";
export default {
  data() {
    return {
      book_list: [],
      book_listn: [],
      book_listcb: [],
      url: "",
      url1: "",
      url2: "",
      url3: "",
      title: "",
      isLoading: true,
    };
  },
  components: {
    Loading
  },
  methods: {
    async csfes() {
      await phFunc().then((res) => {
        let { list } = res.data;
        let nlist = list[0].subNavis[1].naviInfos[0];
        let nvlist = list[1].subNavis[1].naviInfos[0];
        let cblist = list[2].subNavis[1].naviInfos[0];
        this.url1=nlist.url
        this.url2=nvlist.url
        this.url3=cblist.url
        reFunc(nlist.url).then((lis) => {
          let { list } = lis;
          this.book_list = list.map((item) => {
            return item;
          });
        }).catch(err => {
          console.log("请求失败...");
        });
        reFunc(nvlist.url).then((lis) => {
          let { list } = lis;
          this.book_listn = list.map((item) => {
            return item;
          });
        }).catch(err => {
          console.log("请求失败...");
        });
        reFunc(cblist.url).then((lis) => {
          let { list } = lis;
          this.book_listcb = list.map((item) => {
            return item;
          });
        }).catch(err => {
          console.log("请求失败...");
        });
        this.isLoading = false;
      }).catch(err => {
          console.log("请求失败...");
        });
    },
    gettitl(e) {
      if (e.target.textContent === "更多") {
        this.title = e.target.parentNode.firstChild.textContent;
        let n = document.querySelectorAll(".gradient")[0].textContent;
        let nv = document.querySelectorAll(".gradient")[1].textContent;
        let tus = document.querySelectorAll(".gradient")[2].textContent;
        if (this.title === n) {
          this.url=this.url1
        }else  if (this.title === nv) {
          this.url=this.url2
        }else  if (this.title === tus) {
          this.url=this.url3
        }
      }
      // console.log(this.title);
      let titles = this.title;
      let urls = this.url;
      this.$router.push(`/modoph?list_title=${titles}&url=${urls}`);
    },
  },
  created() {
    this.csfes();
  },
};
</script>
<style lang="scss">
@import url(../../static/css/reset.css);
.em-1 {
  display: inline-block;
  width: 16px;
  height: 20px;
  text-align: center;
  float: left;
  font-weight: bold;
  margin-right: 10px;
  text-align: center;
  &.top-1 {
    font-size: 9px;
    position: absolute;
    text-indent: -2px;
    top: 7px;
    left: 5%;
    color: #fff;
    background: url(../../static/imgs/top1.png);
    background-repeat: no-repeat;
    background-size: cover;
  }
  &.top-2 {
    text-indent: -2px;
    color: #fff;
    background: url(../../static/imgs/top2.png);
    background-repeat: no-repeat;
    background-size: cover;
  }
  &.top-3 {
    text-indent: -2px;
    color: #fff;
    background: url(../../static/imgs/top3.png);
    background-repeat: no-repeat;
    background-size: cover;
  }
}
.phnanp {
  margin: auto 5%;
  margin-top: 3px;
  .hed {
    width: 100%;
    h3 {
      height: 28px;
      line-height: 28px;
      margin-bottom: 16px;
      font-weight: bold;
      .gradient {
        float: left;
        display: inline-block;
        font-size: 20px;
        color: #1a1a1a;
      }
      .more {
        float: right;
        padding: 0 17px;
        font-size: 13px;
        font-weight: normal;
        color: #999;
        box-sizing: border-box;
        border: 1px solid #f0f0f0;
        border-radius: 28px;
      }
    }
    .booklist {
      margin-top: 20px;
      width: 100%;
      // background: black;
      ul {
        li {
          display: flex;
          width: 100%;
          position: relative;
          [class^="book"] {
            width: 93px;
            margin: 9px;
            float: left;
            img {
              width: 94px;
              height: 132px;
              border-radius: 5px;
            }
          }
          [class^="text"] {
            padding-top: 10px;
            color: #333;
            outline: none;
            padding-left: 10px;
            text-align: start;
            h4 {
              font-size: 15px;
              line-height: 19px;
              height: 38px;
              max-height: 38px;
            }
            [class^="name"] {
              color: #888;
              height: 17px;
              line-height: 17px;
              font-size: 12px;
              margin-bottom: 5px;
              -webkit-line-clamp: 2;
              overflow: hidden;

              span {
                float: left;
                display: inline-block;
                height: 18px;
                line-height: 18px;
              }
            }
            [class^="p"] {
              color: #888;
              line-height: 16px;
              height: 17px;
              -webkit-line-clamp: 2;
              display: -webkit-box;
              -webkit-box-orient: vertical;
              overflow: hidden;
              text-overflow: ellipsis;
            }
            [class^="tag"] {
              padding-top: 13px;
              span {
                display: inline-block;
                margin-right: 2px;
                padding: 0 12px;
                height: 22px;
                line-height: 22px;
                font-size: 12px;
                color: #999;
                background-image: linear-gradient(
                  3deg,
                  #f9f9f9 0,
                  #f0f0f0 100%
                );
                border-radius: 22px;
              }
            }
          }
        }
      }
    }
  }
}
</style>
  